home *** CD-ROM | disk | FTP | other *** search
/ Browser - Artopolis 97 / browser.iso / mac / artrope / artrope.dir / 00008_Script_Scroll Text Parent < prev    next >
Text File  |  1997-10-08  |  6KB  |  185 lines

  1. property textMember, textSprite, barSprite, markSprite, markHeight, memberHeight, barHeight
  2.  
  3. ---------------------------------------------------------------
  4. --  PROPERTIES
  5. --textMember = the current text member
  6. --textSprite = the sprite the text sits in
  7. --barSprite = the scroll bar
  8. --markSprite = the marker that slides along barSprite
  9. --markHeight = the height of the marker/slider; needed for positioning marker
  10. --memberHeight = the height of the text member
  11. --barHeight = the height of the scroll bar the slider moves along
  12. --
  13. --code is derived from Gary Rozenweig's "The Director 6.0 Book"
  14. ---------------------------------------------------------------
  15.  
  16. --==================================
  17. --from the initFrame the scrollObject is created, passed
  18. --the spriteNums for the below
  19. ------------------------------------
  20. on new me, textSprite0, barSprite0, markSprite0
  21.   set textSprite = textSprite0
  22.   set textMember = the member of sprite textSprite
  23.   set barSprite = barSprite0
  24.   set markSprite = markSprite0
  25.   set the scrollTop of member textMember = 0
  26.   put the height of the rect of sprite markSprite into markHeight
  27.   put the height of the rect of textMember into memberHeight
  28.   put the height of the rect of sprite barSprite into barHeight
  29.   puppetSprite markSprite, TRUE
  30.   setMark(me)
  31.   return me
  32. end
  33.  
  34.  
  35. --==================================
  36. --set the scrolltop of current textmember to 0
  37. --depuppets the marker so it resets its position
  38. ------------------------------------
  39. on resetMyStuff me
  40.   set the scrollTop of textMember = 0
  41.   puppetSprite markSprite, FALSE
  42. end
  43.  
  44.  
  45. --==================================
  46. ------------------------------------
  47. on scrollOne me, x
  48.   scrollRichTextLine textMember, x
  49.   setMark(me)
  50.   updateStage
  51.   
  52.   put the ticks into t
  53.   
  54.   -- continue to scroll fast
  55.   repeat while the stillDown 
  56.     if the ticks < t + 15 then next repeat  -- delay after first movement   
  57.     scrollRichTextLine textMember, x
  58.     setMark(me)
  59.     updateStage
  60.   end repeat
  61. end
  62.  
  63.  
  64. --==================================
  65. --positions the markerSprite along the barSprite
  66. ------------------------------------
  67. on setMark me
  68.   
  69.   -- figure out where in the text field we are
  70.   put float(the scrollTop of textMember)/(memberHeight) into percent
  71.   
  72.   -- set the mark to be in the right spot in along the bar
  73.   set the locV of sprite markSprite = the top of sprite barSprite + percent*(barHeight-markHeight)+(markHeight/2) 
  74.   
  75. end
  76.  
  77.  
  78. --==================================
  79. --if the marker is clicked then we move the
  80. --marker and the text while the mouseDown
  81. ------------------------------------
  82. on moveMark me
  83.   
  84.   repeat while the stillDown
  85.     -- constainly check teh vertical position of the mouse and set the field and mark
  86.     put the mouseV into v
  87.     put max(the top of sprite barSprite + markHeight/2,v) into v -- top limit
  88.     put min(the bottom of sprite barSprite - markHeight/2,v) into v -- bottom limit
  89.     set the locV of sprite markSprite = v
  90.     put float(v-the top of sprite barSprite-markHeight/2)/(barHeight-markHeight) into percent
  91.     set the scrollTop of textMember = (memberHeight*percent)
  92.     updateStage
  93.   end repeat
  94.   
  95. end
  96.  
  97.  
  98. --==================================
  99. -- when the user clicks on the bar, jump up or down by pages 
  100. --until the spot clicked is hit 
  101. ------------------------------------
  102. on clickBar me
  103.     put the locV of the clickLoc into v
  104.   -- scroll down by page
  105.   if v > the locV of sprite markSprite then
  106.     scrollRichTextPage textMember, 1
  107.     setMark(me)
  108.     updateStage
  109.     
  110.     --delay after first movement
  111.     put the ticks into t
  112.     repeat while the ticks < t + 15
  113.     end repeat
  114.     
  115.     -- continue to scroll fast
  116.     repeat while the stillDown and v > the locV of sprite markSprite
  117.       scrollRichTextPage textMember, 1
  118.       setMark(me)
  119.       updateStage
  120.     end repeat
  121.     
  122.     -- scroll up by page  
  123.   else    
  124.     scrollRichTextPage textMember, -1
  125.     setMark(me)
  126.     updateStage
  127.     
  128.     --delay after first movement
  129.     put the ticks into t
  130.     repeat while the ticks < t + 15
  131.     end repeat
  132.     
  133.     -- continue to scroll fast
  134.     repeat while the stillDown and v < the locV of sprite markSprite
  135.       scrollRichTextPage textMember, -1
  136.       setMark(me)
  137.       updateStage
  138.     end repeat
  139.   end if
  140. end
  141.  
  142.  
  143. --==================================
  144. --scrolls the text by line
  145. --called from up/down arrows
  146. ------------------------------------
  147. on scrollRichTextLine whichMember, x
  148.   put 14 into h -- the number of pixels in a line
  149.   if x = -1 then
  150.     if the scrollTop of whichMember - h < 0 then
  151.       set the scrollTop of whichMember = 0
  152.     else
  153.       set the scrollTop of whichMember = the scrollTop of whichMember - h
  154.     end if
  155.   else
  156.     if the scrollTop of whichMember + h > the height of whichMember-h then
  157.       set the scrollTop of whichMember = the height of whichMember- h
  158.     else
  159.       set the scrollTop of whichMember = the scrollTop of whichMember + h
  160.     end if
  161.   end if  
  162. end
  163.  
  164.  
  165. --==================================
  166. --when the barSprite is clicked, we 
  167. --scroll by line.
  168. ------------------------------------
  169. on scrollRichTextPage whichMember, x
  170.   put the height of the rect of sprite textSprite into h -- the number of pixels in a line
  171.   if x = -1 then
  172.     if the scrollTop of whichMember - h < 0 then
  173.       set the scrollTop of whichMember = 0
  174.     else
  175.       set the scrollTop of whichMember = the scrollTop of whichMember - h
  176.     end if
  177.   else
  178.     if the scrollTop of whichMember + h > the height of whichMember-h then
  179.       set the scrollTop of whichMember = the height of whichMember- h
  180.     else
  181.       set the scrollTop of whichMember = the scrollTop of whichMember + h
  182.     end if
  183.   end if  
  184. end
  185.